package com.pet.seller.controller;


import com.pet.seller.mapper.OrdersMapper;
import com.pet.seller.mapper.SellerMapper;
import com.pet.seller.model.Orders;
import com.pet.seller.model.OrdersExample;
import com.pet.seller.model.SellerExample;
import com.pet.seller.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
public class SignInController {
    @Autowired
    private SellerMapper sellerMapper;


    @RequestMapping(value="/signin",method = RequestMethod.POST)
    public String signin(HttpServletRequest request, Model model) {
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        String passMd5 = Md5Util.MD5(password);
        SellerExample sellerExample = new SellerExample();
        sellerExample.createCriteria().andEmailEqualTo(email).andPasswordEqualTo(passMd5);
        int i = sellerMapper.countByExample(sellerExample);
        if(i>0){
            request.getSession().setAttribute("sellerEmail",email);
            return "OK";
        }else{
            return "FALSE";
        }
    }



}